package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;

/**
 * 攻略的文章
 * 大攻略--攻略的分类--文章
 */
@Setter@Getter
public class StrategyDetail extends BaseDomain{

    public static final int STATE_NORMAL=1;//不发布
    public static final int STATE_RELEASE=2;//发布


    private String title;//标题
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date createTime;//创建时间
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date releaseTime;//发布时间

    private Integer sequence;//序号

    private StrategyCatalog catalog;//攻略的分类

    private Long strategyId;

    private String coverUrl;//封面

    private Integer state=1;//状态

    private StrategyContent content;

    public String getStateName(){
        if(state!=null){
            if (state==STATE_NORMAL) {
                return "不发布";
            }
            return "发布";
        }
        return "";
    }

    public String getJsonString(){
        HashMap<Object, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("title", title);
        map.put("sequence", sequence);
        map.put("coverUrl", coverUrl);
        map.put("state", state);
        map.put("strategyId", strategyId);
        if (catalog != null) {
            map.put("catalogId", catalog.id);
        }
        return JSONUtil.toJSONString(map);
    }
}